<template>
  <div class="screen-adapter" v-if="showInfo">
    <div class="adapter-info">
      <div class="info-item">
        <span class="label">屏幕尺寸:</span>
        <span class="value">{{ screenInfo.width }} × {{ screenInfo.height }}</span>
      </div>
      <div class="info-item">
        <span class="label">设备类型:</span>
        <span class="value">{{ getDeviceTypeText(screenInfo.deviceType) }}</span>
      </div>
      <div class="info-item">
        <span class="label">缩放比例:</span>
        <span class="value">{{ (screenInfo.scale * 100).toFixed(0) }}%</span>
      </div>
      <div class="info-item">
        <span class="label">全屏状态:</span>
        <span class="value">{{ screenInfo.isFullscreen ? '是' : '否' }}</span>
      </div>
    </div>
    <div class="adapter-controls">
      <button @click="toggleFullscreen" class="control-btn">
        {{ screenInfo.isFullscreen ? '退出全屏' : '进入全屏' }}
      </button>
      <button @click="toggleInfo" class="control-btn">
        {{ showInfo ? '隐藏信息' : '显示信息' }}
      </button>
    </div>
  </div>
  <div v-else class="adapter-toggle" @click="toggleInfo">
    <div class="toggle-icon">📱</div>
  </div>
</template>

<script>
import fullScreenAdapter from '@/utils/fullScreenAdapter'

export default {
  name: 'ScreenAdapter',
  data() {
    return {
      showInfo: false,
      screenInfo: {}
    }
  },
  mounted() {
    this.updateScreenInfo()
    this.bindEvents()
  },
  beforeDestroy() {
    this.unbindEvents()
  },
  methods: {
    updateScreenInfo() {
      this.screenInfo = fullScreenAdapter.getScreenInfo()
    },
    bindEvents() {
      window.addEventListener('resize', this.updateScreenInfo)
      document.addEventListener('fullscreenchange', this.updateScreenInfo)
    },
    unbindEvents() {
      window.removeEventListener('resize', this.updateScreenInfo)
      document.removeEventListener('fullscreenchange', this.updateScreenInfo)
    },
    toggleFullscreen() {
      fullScreenAdapter.toggleFullscreen()
    },
    toggleInfo() {
      this.showInfo = !this.showInfo
    },
    getDeviceTypeText(type) {
      const typeMap = {
        'ultrawide': '超宽屏',
        'desktop': '桌面',
        'laptop': '笔记本',
        'tablet': '平板',
        'mobile': '手机'
      }
      return typeMap[type] || '未知'
    }
  }
}
</script>

<style scoped>
.screen-adapter {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(0, 212, 255, 0.3);
  border-radius: 8px;
  padding: 15px;
  z-index: 1000;
  min-width: 200px;
  max-height: 80vh;
  overflow-y: auto;
}

.adapter-info {
  margin-bottom: 15px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
}

.info-item:last-child {
  margin-bottom: 0;
}

.label {
  color: rgba(255, 255, 255, 0.8);
}

.value {
  color: #00d4ff;
  font-weight: bold;
}

.adapter-controls {
  display: flex;
  gap: 10px;
}

.control-btn {
  flex: 1;
  padding: 8px 12px;
  background: rgba(0, 212, 255, 0.1);
  border: 1px solid rgba(0, 212, 255, 0.3);
  border-radius: 4px;
  color: #00d4ff;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.control-btn:hover {
  background: rgba(0, 212, 255, 0.2);
  border-color: #00d4ff;
}

.adapter-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(0, 212, 255, 0.3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  transition: all 0.3s ease;
}

.adapter-toggle:hover {
  background: rgba(0, 212, 255, 0.1);
  border-color: #00d4ff;
}

.toggle-icon {
  font-size: 16px;
}

/* 响应式适配 */
@media (max-width: 768px) {
  .screen-adapter {
    top: 10px;
    right: 10px;
    left: 10px;
    min-width: auto;
  }
  
  .adapter-toggle {
    top: 10px;
    right: 10px;
    width: 35px;
    height: 35px;
  }
  
  .toggle-icon {
    font-size: 14px;
  }
}
</style>
